package cc.yugu.yhdw.webserver.service.hdw;
import cc.yugu.yhdw.common.domain.basic.DictCategory;
import cc.yugu.yhdw.common.domain.hdw.ExchangePacketOrder;
import cc.yugu.yhdw.common.entity.pagination.Page;
import cc.yugu.yhdw.webserver.persistence.hdw.ExchangePacketOrderMapper;
import cc.yugu.yhdw.webserver.service.AbstractService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
/**
 * 换电套餐订单业务
 * 
 * @Date:Created in 2018/7/9 13:48
 * @Author:
 * @Modified By: zjn 2018/7/9 13:48
 */ 
@Service
public class ExchangePacketOrderService extends AbstractService{

    @Autowired
    ExchangePacketOrderMapper exchangePacketOrderMapper;
    /**
    * 分页查询
    * 
    * @Param: [search]
    * @Return: cc.yugu.yhdw.common.entity.pagination.Page
    * @Author By: zjn 2018/7/9  13:48
    */ 
    public Page findPage(ExchangePacketOrder search) {
        Page page = search.buildPage();
        page.setTotalItems(exchangePacketOrderMapper.findPageCounts(search));
        search.setBeginIndex(page.getOffset());
        List<ExchangePacketOrder> list = exchangePacketOrderMapper.findPageResults(search);
        for (ExchangePacketOrder packetPeriodOrder: list) {
            Integer agentId = packetPeriodOrder.getAgentId();
            Integer agencyId = packetPeriodOrder.getAgencyId();
            // 设置运营商名称
            if (agentId != null) {
                if (findAgentInfo(agentId) != null) {
                    // 非常耗费时间
                    packetPeriodOrder.setAgentName(findAgentInfo(agentId).getAgentName());
                }
            }
            // 设置代理商名称
            if (agencyId != null) {
                if (findAgency(agencyId) != null) {
                    packetPeriodOrder.setAgencyName(findAgency(agencyId).getAgencyName());
                }
            }
        }
        page.setResult(list);
        return page;
    }

    public ExchangePacketOrder find(String id) {
        return exchangePacketOrderMapper.find(id);
    }

}
